﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BussinessLogicTecnoPez;
using BussinessLogicTecnoPez.Produccion.Clasificacion_e_Incubacion;
using Tecnopez.Globals;

public partial class Modules_EnfermedadesControlEstanque_RegistrarControles : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        inicializarGrilla();
        if (Page.IsPostBack == false)
        {
            GenericMasterPage master = (GenericMasterPage)this.Master;
            master.Imagen = "../Styles/Icons/controls.png";
            master.Titulo = "Gestión de Controles a Estanques.";
        }
    }

    private void inicializarGrilla()
    {
        DataControlField[] extraButtons = new DataControlField[1];
        ButtonField colB = new ButtonField();
        colB.ButtonType = ButtonType.Image;
        colB.ImageUrl = Functions.getHost(this.Page) + "Styles/Icons/lupa.png";
        colB.HeaderText = "";
        colB.CommandName = "Selleccionar";
        colB.HeaderStyle.Width = 5;
        colB.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
        extraButtons[0] = colB;

        TDGEstanque.setupGrid(typeof(Estanque),cargarGrillaEstanque,true,true,this.ViewState);
    }

    private void cargarGrillaEstanque()
    {
        Estanque.getManager.ClearFilters();
        Estanque.getManager.ClearOrders();

        Estanque.getManager.AddFilter("ubicacion", GenericManager<Estanque>.filterOperator.Like, txtBuscar.Text + "%");

        if (ViewState[TDGEstanque.PageDataViewOrderKey] == null)
        {
            Estanque.getManager.AddOrder("IDESTANQUE", GenericManager<Estanque>.Order.orderDirection.DESC);
        }
        else
        {
            if (ViewState[TDGEstanque.PageDataViewOrderKey].ToString() == "tipoDeEstanqueDesc")
            {
                Estanque.getManager.AddOrder("tipoDeEstanqueInt", (GenericManager<Estanque>.Order.orderDirection)ViewState[TDGEstanque.PageDataViewOrdenDireccionKey]);
            }
            else if (ViewState[TDGEstanque.PageDataViewOrderKey].ToString() == "habilitadoString")
            {
                Estanque.getManager.AddOrder("habilitado", (GenericManager<Estanque>.Order.orderDirection)ViewState[TDGEstanque.PageDataViewOrdenDireccionKey]);
            }
            else
            {
                Estanque.getManager.AddOrder(ViewState[TDGEstanque.PageDataViewOrderKey].ToString(), (GenericManager<Estanque>.Order.orderDirection)ViewState[TDGEstanque.PageDataViewOrdenDireccionKey]);
            }
        }

        List<Estanque> lista = new List<Estanque>();

        lista = Estanque.getManager.GetFilter();
        TDGEstanque.DataSource=lista;
        TDGEstanque.DataBind();
    }

    protected void cmdBuscar_Click(object sender, EventArgs e)
    {

    }
    protected void TDGEstanque_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "ver")
        {
            cargarGrillaEstanque();
            int fila = Convert.ToInt32(e.CommandArgument);
            int estanque = Convert.ToInt32(TDGEstanque.DataKeys[fila].Value);

            Response.Redirect("ControlesPorEstanques.aspx?idEstanque=" + estanque.ToString());
        }
    }
}
